@extends('backstage.layout.master')
@section('title', '轮播图列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                轮播图列表
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-content">
                    <div class="page-header">
                        <h1>
                            轮播图列表
                        </h1>
                        <a href="backstage/carousels/add"><button class="btn btn-danger add-btn-danger" style="float: right;">添加</button></a>
                    </div><!-- /.page-header -->

                    <div class="row">
                        <div class="col-xs-12">
                            <!-- PAGE CONTENT BEGINS -->
                            <div class="table-responsive">
                                <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>降序排列</th>
                                        <th>轮播图</th>
                                        <th>类型</th>
                                        <th class="hidden-480">状态</th>
                                        <th>开始时间</th>
                                        <th>结束时间</th>
                                        <th>当前状态</th>
                                        <th>资源状态</th>
                                        <th>
                                            <i class="icon-time bigger-110 hidden-480"></i>
                                            更新时间
                                        </th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach ($carousels as $carousel)
                                        <tr>
                                            <td style="width:68px;">
                                                <input type="text" name="sort" value="{{$carousel->sort}}" class="sort"
                                                       style="width:50px;" data="{{$carousel->sort}}"
                                                       data-module-id="{{$carousel->carousel_id}}"
                                                       onblur="updateModule(this,2);">
                                            </td>
                                            <td>
                                                <img style="width:300px;" src="{{$carousel->carousel_image}}"/>
                                            </td>
                                            <td>
                                                @if ($carousel->carousel_type == 1)
                                                    产品详情
                                                @elseif($carousel->carousel_type == 2)
                                                    产品模板
                                                @elseif($carousel->carousel_type == 3)
                                                    外链
                                                @elseif($carousel->carousel_type == 4)
                                                    帮助系统
                                                @endif
                                            </td>
                                            <td class="hidden-480">
                                                @if ($carousel->state == 1)
                                                    <span class="label label-sm label-warning display_span"
                                                          style="cursor:pointer; display: block;" data="{{$carousel->state}}"
                                                          data-module-id="{{$carousel->carousel_id}}"onclick="updateModule(this,1);">
                                                            显示
                                                        </span>
                                                @elseif ($carousel->state == 0)
                                                    <span class="label label-sm label-inverse arrowed-in display_span"
                                                          style="cursor:pointer;display: block;" data="{{$carousel->state}}"
                                                          data-module-id="{{$carousel->carousel_id}}"onclick="updateModule(this,1);">
                                                            隐藏
                                                        </span>
                                                @endif
                                            </td>
                                            <td class="hidden-480">{{date('Y-m-d H:i:s',$carousel->begin)}}</td>
                                            <td class="hidden-480">{{date('Y-m-d H:i:s',$carousel->end)}}</td>
                                            <td>
                                                @if($carousel->is_end == 0)
                                                    <p style="color:red;">已经结束</p>
                                                @elseif($carousel->is_end == 1)
                                                    <p>正在进行</p>
                                                @else
                                                    <p style="color:blue;">还未开始</p>
                                                @endif
                                            </td>
                                            <td>
                                                @if($carousel->resource_state == 1)
                                                    <a class="red">模板库存不足</a>
                                                    @elseif($carousel->resource_state == 2)
                                                    <a class="red">设计师或者品牌商允许出售数量不足</a>
                                                    @elseif($carousel->resource_state == 3)
                                                    <a class="red">产品已下架</a>
                                                    @elseif($carousel->resource_state == 4)
                                                    <a class="red">资源不存在或被删除</a>
                                                    @elseif($carousel->resource_state == 5)
                                                    <a class="red">模板被删除</a>
                                                    @elseif($carousel->resource_state == 6)
                                                    <a class="red">该产品所使用的素材或字体存在异常</a>
                                                @endif
                                            </td>
                                            <td>
                                                {{date('Y-m-d H:i:s',$carousel->updated_at)}}
                                            </td>
                                            <td>
                                                <a class="blue" href="backstage/carousels/update/{{$carousel->carousel_id}}">编辑</a>
                                                <a href="javascript:;" class="red" data-module-id="{{$carousel->carousel_id}}" onclick="updateModule(this,3);">删除</a>
                                            </td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            </div>
                            <div class="row">
                                <div class="col-sm-6">
                                    <div class="dataTables_info" id="sample-table-2_info"></div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="dataTables_paginate paging_bootstrap">
                                        <?php echo $carousels->render(); ?>
                                    </div>
                                </div>
                            </div>
                            <!-- PAGE CONTENT ENDS -->
                        </div><!-- /.col -->
                    </div><!-- /.row -->
                </div><!-- /.page-content -->
            </div>
        </div>
    </div>
@stop
@section('script')
    <script type="text/javascript">
        var flag = 1;
        $(function () {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
        });
        function updateModule(th, type) {
            if (type == 1) {
                //修改显示
                var is_show = $(th).attr("data") == 1 ? 0 : 1;
                show(th, is_show, $(th).attr("data-module-id"));
            } else if (type == 2) {
                //修改排序
                var newsort = $(th).val();
                var oldsort = $(th).attr('data');
                if (newsort == oldsort) {
                    return false;
                }
                changeSort(th, newsort, $(th).attr("data-module-id"));
            } else {
                //删除
                if (confirm('确认删除吗？')) {
                    deleteModule(th, $(th).attr("data-module-id"));
                }
            }
        }
        function show(th, is_show, carousel_id) {
            if (flag == 1) {
                flag = 0;
                $.ajax({
                    type: "POST",
                    url: "backstage/carousels/show",
                    data: {"state": is_show, "carousel_id": carousel_id},
                    success: function (msg) {
                        flag = 1;
                        if (msg.state == "M00000") {
                            $(th).attr("data", msg.result.is_show);
                            showMessage("", msg.message);
                            window.location.reload();
                        } else {
                            showMessage(msg.message, "");
                        }
                    },
                    error: function () {
                        flag = 1;
                        showMessage("修改失败!", "");
                    }
                });
            }
        }
        function changeSort(th, sort, carousel_id) {
            if (flag == 1) {
                flag = 0;
                $.ajax({
                    type: "POST",
                    url: "backstage/carousels/update-sort",
                    data: {"sort": sort, "carousel_id": carousel_id},
                    success: function (msg) {
                        flag = 1;
                        if (msg.state == "M00000") {
                            $(th).attr("data", msg.result.sort);
                            showMessage("", msg.message);
                        } else {
                            showMessage(msg.message, "");
                        }
                    },
                    error: function () {
                        flag = 1;
                        showMessage("修改失败!", "");
                    }
                });
            }
        }
        function deleteModule(th, carousel_id) {
            if (flag == 1) {
                flag = 0;
                $.ajax({
                    type: "POST",
                    url: "backstage/carousels/delete",
                    data: {"carousel_id": carousel_id},
                    success: function (msg) {
                        flag = 1;
                        if (msg.state == "M00000") {
                            showMessage("", msg.message);
                            window.location.reload();
                        } else {
                            showMessage(msg.message, "");
                        }
                    },
                    error: function () {
                        flag = 1;
                        showMessage("修改失败!", "");
                    }
                });
            }
        }
    </script>


@stop